﻿using System;
using System.ComponentModel;

namespace ExFlash.Records
{
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class MorphLineStyle2 : MorphLineStyle
    {
        public CapStyles StartCapStyle
        {
            get;
            protected set;
        }

        public JoinStyles JoinStyle
        {
            get;
            protected set;
        }

        public Boolean HasFillFlag
        {
            get;
            protected set;
        }

        public Boolean NoHScaleFlag
        {
            get;
            protected set;
        }

        public Boolean NoVScaleFlag
        {
            get;
            protected set;
        }

        public Boolean PixelHuntingFlag
        {
            get;
            protected set;
        }

        public Boolean NoClose
        {
            get;
            protected set;
        }

        public CapStyles EndCapStyle
        {
            get;
            protected set;
        }

        public ushort MiterLimitFactor
        {
            get;
            protected set;
        }

        public MorphFillStyle FillType
        {
            get;
            protected set;
        }

        public override void SwfDeserialize(BinaryBitReader reader)
        {
            StartWidth = reader.ReadUInt16();

            EndWidth = reader.ReadUInt16();

            StartCapStyle = (CapStyles)reader.ReadUInt32(2);
            JoinStyle = (JoinStyles)reader.ReadUInt32(2);
            HasFillFlag = reader.ReadBoolean();
            NoHScaleFlag = reader.ReadBoolean();
            NoVScaleFlag = reader.ReadBoolean();
            PixelHuntingFlag = reader.ReadBoolean();
            reader.SkipBits(5);
            NoClose = reader.ReadBoolean();
            EndCapStyle = (CapStyles)reader.ReadUInt32(2);

            reader.AlignBits();

            if (JoinStyle == JoinStyles.MiterJoin)
            {
                MiterLimitFactor = reader.ReadUInt16();
            }

            if (!HasFillFlag)
            {
                StartColor = new RGBARecord();
                StartColor.SwfDeserialize(reader);

                EndColor = new RGBARecord();
                EndColor.SwfDeserialize(reader);
            }
            else
            {
                FillType = new MorphFillStyle();
                FillType.SwfDeserialize(reader);
            }
        }
    }
}
